package com.inmobi.commons.thinICE.icedatacollector;

import android.app.Activity;
import android.net.wifi.ScanResult;
import android.os.Build.VERSION;
import android.os.Handler;
import android.util.Log;
import com.inmobi.commons.thinICE.cellular.CellOperatorInfo;
import com.inmobi.commons.thinICE.cellular.CellUtil;
import com.inmobi.commons.thinICE.location.LocationInfo;
import com.inmobi.commons.thinICE.location.LocationUtil;
import com.inmobi.commons.thinICE.wifi.WifiInfo;
import com.inmobi.commons.thinICE.wifi.WifiScanListener;
import com.inmobi.commons.thinICE.wifi.WifiScanner;
import com.inmobi.commons.thinICE.wifi.WifiUtil;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

final class a
  implements Runnable
{
  public void run()
  {
    if (BuildSettings.DEBUG)
      Log.d("IceDataCollector", "** sample runnable");
    if (IceDataCollector.c() == null)
    {
      if (BuildSettings.DEBUG)
        Log.w("IceDataCollector", "sampling when looper is null, exiting");
      return;
    }
    if ((Build.VERSION.SDK_INT < 14) && (!IceDataCollector.d().hasWindowFocus()))
    {
      if (BuildSettings.DEBUG)
        Log.d("IceDataCollector", "activity no longer has focus, terminating");
      IceDataCollector.b();
      LinkedList localLinkedList = IceDataCollector.e();
      IceDataCollector.flush();
      IceDataCollector.a(null);
      IceDataCollector.a(null);
      if (IceDataCollector.f() != null)
        IceDataCollector.f().onSamplingTerminated(localLinkedList);
      IceDataCollector.a(null);
      return;
    }
    IceDataCollector.i().postDelayed(IceDataCollector.g(), IceDataCollector.h().getSampleInterval());
    if (BuildSettings.DEBUG)
      Log.d("IceDataCollector", "next sample in " + IceDataCollector.h().getSampleInterval() + " ms");
    Sample localSample = new Sample();
    int i = IceDataCollector.h().getWifiFlags();
    boolean bool1 = ThinICEConfigSettings.bitTest(i, 2);
    final boolean bool2 = false;
    if (!bool1)
      bool2 = true;
    final boolean bool3 = ThinICEConfigSettings.bitTest(i, 1);
    int j = IceDataCollector.h().getCellOpFlags();
    boolean bool4 = ThinICEConfigSettings.bitTest(j, 1);
    boolean bool5 = ThinICEConfigSettings.bitTest(j, 2);
    if (IceDataCollector.h().isSampleCellOperatorEnabled());
    try
    {
      CellOperatorInfo localCellOperatorInfo = CellUtil.getCellNetworkInfo(IceDataCollector.j());
      if (bool4)
      {
        localCellOperatorInfo.simMcc = -1;
        localCellOperatorInfo.simMnc = -1;
      }
      if (bool5)
      {
        localCellOperatorInfo.currentMcc = -1;
        localCellOperatorInfo.currentMnc = -1;
      }
      if (BuildSettings.DEBUG)
        Log.d("IceDataCollector", "-- cell operator: " + localCellOperatorInfo);
      localSample.cellOperator = localCellOperatorInfo;
      if (!IceDataCollector.h().isSampleCellEnabled());
    }
    catch (Exception localException3)
    {
      try
      {
        if (CellUtil.hasGetCurrentServingCellPermission(IceDataCollector.j()))
        {
          String str = CellUtil.getCurrentServingCell(IceDataCollector.j());
          if (BuildSettings.DEBUG)
            Log.d("IceDataCollector", "-- current serving cell: " + str);
          localSample.servingCellId = str;
          label383: localSample.connectedWifiAp = IceDataCollector.getConnectedWifiInfo(IceDataCollector.j());
          if (IceDataCollector.h().isSampleLocationEnabled())
            try
            {
              if (!LocationUtil.hasLocationPermission(IceDataCollector.j()))
                break label683;
              localHashMap = LocationUtil.getLastKnownLocations(IceDataCollector.j());
              if (!BuildSettings.DEBUG)
                break label674;
              Log.d("IceDataCollector", "-- locations:");
              Iterator localIterator = localHashMap.values().iterator();
              while (localIterator.hasNext())
              {
                LocationInfo localLocationInfo = (LocationInfo)localIterator.next();
                Log.d("IceDataCollector", "   + " + localLocationInfo);
              }
            }
            catch (Exception localException2)
            {
              if (BuildSettings.DEBUG)
                Log.e("IceDataCollector", "Error getting location data", localException2);
            }
          label514: if (!IceDataCollector.h().isSampleVisibleWifiEnabled());
        }
      }
      catch (Exception localException3)
      {
        label674: label683: label741: 
        try
        {
          HashMap localHashMap;
          if (WifiUtil.hasWifiScanPermission(IceDataCollector.j(), false))
            WifiScanner.requestScan(IceDataCollector.j(), new a(bool2, bool3));
          while (true)
          {
            synchronized (IceDataCollector.k())
            {
              IceDataCollector.a(localSample);
              if (IceDataCollector.e() == null)
                break label741;
              IceDataCollector.e().add(localSample);
              if (IceDataCollector.e().size() <= IceDataCollector.h().getSampleHistorySize())
                break label741;
              IceDataCollector.e().removeFirst();
            }
            localException4 = localException4;
            if (!BuildSettings.DEBUG)
              break;
            Log.e("IceDataCollector", "Error getting cell operator data", localException4);
            break;
            if (!BuildSettings.DEBUG)
              break label383;
            Log.w("IceDataCollector", "application does not have permission to access current serving cell");
            break label383;
            localException3 = localException3;
            if (!BuildSettings.DEBUG)
              break label383;
            Log.e("IceDataCollector", "Error getting cell data", localException3);
            break label383;
            localSample.lastKnownLocations = localHashMap;
            break label514;
            if (!BuildSettings.DEBUG)
              break label514;
            Log.w("IceDataCollector", "application does not have permission to access location");
            break label514;
            if (BuildSettings.DEBUG)
              Log.w("IceDataCollector", "application does not have permission to scan for wifi access points");
          }
        }
        catch (Exception localException1)
        {
          while (true)
            if (BuildSettings.DEBUG)
              Log.e("IceDataCollector", "Error scanning for wifi", localException1);
        }
      }
    }
  }

  class a
    implements WifiScanListener
  {
    a(boolean paramBoolean1, boolean arg3)
    {
    }

    public void onResultsReceived(List<ScanResult> paramList)
    {
      if (BuildSettings.DEBUG)
        Log.d("IceDataCollector", "Received Wi-Fi scan results " + paramList.size());
      List localList = WifiUtil.scanResultsToWifiInfos(paramList, bool2, bool3);
      if (BuildSettings.DEBUG)
      {
        Log.d("IceDataCollector", "-- wifi scan:");
        Iterator localIterator = localList.iterator();
        while (localIterator.hasNext())
        {
          WifiInfo localWifiInfo = (WifiInfo)localIterator.next();
          Log.d("IceDataCollector", "   + " + localWifiInfo);
        }
      }
      synchronized (IceDataCollector.k())
      {
        if (IceDataCollector.l() != null)
          IceDataCollector.l().visibleWifiAp = localList;
        return;
      }
    }

    public void onTimeout()
    {
      if (BuildSettings.DEBUG)
        Log.w("IceDataCollector", "Received Wi-Fi scan timeout");
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.inmobi.commons.thinICE.icedatacollector.a
 * JD-Core Version:    0.6.2
 */